<?php
if (session_id() == "") session_start(); // Initialize Session data
ob_start(); // Turn on output buffering
?>
<?php include_once "ewcfg10.php" ?>
<?php include_once "ewmysql10.php" ?>
<?php include_once "phpfn10.php" ?>
<?php include_once "stock_articuloinfo.php" ?>
<?php include_once "usuariosinfo.php" ?>
<?php include_once "userfn10.php" ?>
<?php

//
// Page class
//

$stock_articulo_add = NULL; // Initialize page object first

class cstock_articulo_add extends cstock_articulo {

	// Page ID
	var $PageID = 'add';

	// Project ID
	var $ProjectID = "{320446D7-E035-4611-AE9B-94BD19ABA249}";

	// Table name
	var $TableName = 'stock_articulo';

	// Page object name
	var $PageObjName = 'stock_articulo_add';

	// Page name
	function PageName() {
		return ew_CurrentPage();
	}

	// Page URL
	function PageUrl() {
		$PageUrl = ew_CurrentPage() . "?";
		if ($this->UseTokenInUrl) $PageUrl .= "t=" . $this->TableVar . "&"; // Add page token
		return $PageUrl;
	}

	// Message
	function getMessage() {
		return @$_SESSION[EW_SESSION_MESSAGE];
	}

	function setMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_MESSAGE], $v);
	}

	function getFailureMessage() {
		return @$_SESSION[EW_SESSION_FAILURE_MESSAGE];
	}

	function setFailureMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_FAILURE_MESSAGE], $v);
	}

	function getSuccessMessage() {
		return @$_SESSION[EW_SESSION_SUCCESS_MESSAGE];
	}

	function setSuccessMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_SUCCESS_MESSAGE], $v);
	}

	function getWarningMessage() {
		return @$_SESSION[EW_SESSION_WARNING_MESSAGE];
	}

	function setWarningMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_WARNING_MESSAGE], $v);
	}

	// Show message
	function ShowMessage() {
		$hidden = FALSE;
		$html = "";

		// Message
		$sMessage = $this->getMessage();
		$this->Message_Showing($sMessage, "");
		if ($sMessage <> "") { // Message in Session, display
			if (!$hidden)
				$sMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sMessage;
			$html .= "<div class=\"alert alert-success ewSuccess\">" . $sMessage . "</div>";
			$_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
		}

		// Warning message
		$sWarningMessage = $this->getWarningMessage();
		$this->Message_Showing($sWarningMessage, "warning");
		if ($sWarningMessage <> "") { // Message in Session, display
			if (!$hidden)
				$sWarningMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sWarningMessage;
			$html .= "<div class=\"alert alert-warning ewWarning\">" . $sWarningMessage . "</div>";
			$_SESSION[EW_SESSION_WARNING_MESSAGE] = ""; // Clear message in Session
		}

		// Success message
		$sSuccessMessage = $this->getSuccessMessage();
		$this->Message_Showing($sSuccessMessage, "success");
		if ($sSuccessMessage <> "") { // Message in Session, display
			if (!$hidden)
				$sSuccessMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sSuccessMessage;
			$html .= "<div class=\"alert alert-success ewSuccess\">" . $sSuccessMessage . "</div>";
			$_SESSION[EW_SESSION_SUCCESS_MESSAGE] = ""; // Clear message in Session
		}

		// Failure message
		$sErrorMessage = $this->getFailureMessage();
		$this->Message_Showing($sErrorMessage, "failure");
		if ($sErrorMessage <> "") { // Message in Session, display
			if (!$hidden)
				$sErrorMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sErrorMessage;
			$html .= "<div class=\"alert alert-error ewError\">" . $sErrorMessage . "</div>";
			$_SESSION[EW_SESSION_FAILURE_MESSAGE] = ""; // Clear message in Session
		}
		echo "<table class=\"ewStdTable\"><tr><td><div class=\"ewMessageDialog\"" . (($hidden) ? " style=\"display: none;\"" : "") . ">" . $html . "</div></td></tr></table>";
	}
	var $PageHeader;
	var $PageFooter;

	// Show Page Header
	function ShowPageHeader() {
		$sHeader = $this->PageHeader;
		$this->Page_DataRendering($sHeader);
		if ($sHeader <> "") { // Header exists, display
			echo "<p>" . $sHeader . "</p>";
		}
	}

	// Show Page Footer
	function ShowPageFooter() {
		$sFooter = $this->PageFooter;
		$this->Page_DataRendered($sFooter);
		if ($sFooter <> "") { // Footer exists, display
			echo "<p>" . $sFooter . "</p>";
		}
	}

	// Validate page request
	function IsPageRequest() {
		global $objForm;
		if ($this->UseTokenInUrl) {
			if ($objForm)
				return ($this->TableVar == $objForm->GetValue("t"));
			if (@$_GET["t"] <> "")
				return ($this->TableVar == $_GET["t"]);
		} else {
			return TRUE;
		}
	}

	//
	// Page class constructor
	//
	function __construct() {
		global $conn, $Language;
		$GLOBALS["Page"] = &$this;

		// Language object
		if (!isset($Language)) $Language = new cLanguage();

		// Parent constuctor
		parent::__construct();

		// Table object (stock_articulo)
		if (!isset($GLOBALS["stock_articulo"]) || get_class($GLOBALS["stock_articulo"]) == "cstock_articulo") {
			$GLOBALS["stock_articulo"] = &$this;
			$GLOBALS["Table"] = &$GLOBALS["stock_articulo"];
		}

		// Table object (usuarios)
		if (!isset($GLOBALS['usuarios'])) $GLOBALS['usuarios'] = new cusuarios();

		// Page ID
		if (!defined("EW_PAGE_ID"))
			define("EW_PAGE_ID", 'add', TRUE);

		// Table name (for backward compatibility)
		if (!defined("EW_TABLE_NAME"))
			define("EW_TABLE_NAME", 'stock_articulo', TRUE);

		// Start timer
		if (!isset($GLOBALS["gTimer"])) $GLOBALS["gTimer"] = new cTimer();

		// Open connection
		if (!isset($conn)) $conn = ew_Connect();
	}

	// 
	//  Page_Init
	//
	function Page_Init() {
		global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm;

		// Security
		$Security = new cAdvancedSecurity();
		if (!$Security->IsLoggedIn()) $Security->AutoLogin();
		if (!$Security->IsLoggedIn()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}
		$Security->TablePermission_Loading();
		$Security->LoadCurrentUserLevel($this->ProjectID . $this->TableName);
		$Security->TablePermission_Loaded();
		if (!$Security->IsLoggedIn()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}
		if (!$Security->CanAdd()) {
			$Security->SaveLastUrl();
			$this->setFailureMessage($Language->Phrase("NoPermission")); // Set no permission
			$this->Page_Terminate("stock_articulolist.php");
		}

		// Create form object
		$objForm = new cFormObj();
		$this->CurrentAction = (@$_GET["a"] <> "") ? $_GET["a"] : @$_POST["a_list"]; // Set up curent action

		// Global Page Loading event (in userfn*.php)
		Page_Loading();

		// Page Load event
		$this->Page_Load();
	}

	//
	// Page_Terminate
	//
	function Page_Terminate($url = "") {
		global $conn;

		// Page Unload event
		$this->Page_Unload();

		// Global Page Unloaded event (in userfn*.php)
		Page_Unloaded();
		$this->Page_Redirecting($url);

		 // Close connection
		$conn->Close();

		// Go to URL if specified
		if ($url <> "") {
			if (!EW_DEBUG_ENABLED && ob_get_length())
				ob_end_clean();
			header("Location: " . $url);
		}
		exit();
	}
	var $DbMasterFilter = "";
	var $DbDetailFilter = "";
	var $Priv = 0;
	var $OldRecordset;
	var $CopyRecord;

	// 
	// Page main
	//
	function Page_Main() {
		global $objForm, $Language, $gsFormError;

		// Process form if post back
		if (@$_POST["a_add"] <> "") {
			$this->CurrentAction = $_POST["a_add"]; // Get form action
			$this->CopyRecord = $this->LoadOldRecord(); // Load old recordset
			$this->LoadFormValues(); // Load form values
		} else { // Not post back

			// Load key values from QueryString
			$this->CopyRecord = TRUE;
			if (@$_GET["id"] != "") {
				$this->id->setQueryStringValue($_GET["id"]);
				$this->setKey("id", $this->id->CurrentValue); // Set up key
			} else {
				$this->setKey("id", ""); // Clear key
				$this->CopyRecord = FALSE;
			}
			if ($this->CopyRecord) {
				$this->CurrentAction = "C"; // Copy record
			} else {
				$this->CurrentAction = "I"; // Display blank record
				$this->LoadDefaultValues(); // Load default values
			}
		}

		// Set up Breadcrumb
		$this->SetupBreadcrumb();

		// Validate form if post back
		if (@$_POST["a_add"] <> "") {
			if (!$this->ValidateForm()) {
				$this->CurrentAction = "I"; // Form error, reset action
				$this->EventCancelled = TRUE; // Event cancelled
				$this->RestoreFormValues(); // Restore form values
				$this->setFailureMessage($gsFormError);
			}
		}

		// Perform action based on action code
		switch ($this->CurrentAction) {
			case "I": // Blank record, no action required
				break;
			case "C": // Copy an existing record
				if (!$this->LoadRow()) { // Load record based on key
					if ($this->getFailureMessage() == "") $this->setFailureMessage($Language->Phrase("NoRecord")); // No record found
					$this->Page_Terminate("stock_articulolist.php"); // No matching record, return to list
				}
				break;
			case "A": // Add new record
				$this->SendEmail = TRUE; // Send email on add success
				if ($this->AddRow($this->OldRecordset)) { // Add successful
					if ($this->getSuccessMessage() == "")
						$this->setSuccessMessage($Language->Phrase("AddSuccess")); // Set up success message
					$sReturnUrl = $this->getReturnUrl();
					if (ew_GetPageName($sReturnUrl) == "stock_articuloview.php")
						$sReturnUrl = $this->GetViewUrl(); // View paging, return to view page with keyurl directly
					$this->Page_Terminate($sReturnUrl); // Clean up and return
				} else {
					$this->EventCancelled = TRUE; // Event cancelled
					$this->RestoreFormValues(); // Add failed, restore form values
				}
		}

		// Render row based on row type
		$this->RowType = EW_ROWTYPE_ADD;  // Render add type

		// Render row
		$this->ResetAttrs();
		$this->RenderRow();
	}

	// Get upload files
	function GetUploadFiles() {
		global $objForm;

		// Get upload data
	}

	// Load default values
	function LoadDefaultValues() {
		$this->Codigo->CurrentValue = NULL;
		$this->Codigo->OldValue = $this->Codigo->CurrentValue;
		$this->Nombre->CurrentValue = NULL;
		$this->Nombre->OldValue = $this->Nombre->CurrentValue;
		$this->Rubro->CurrentValue = NULL;
		$this->Rubro->OldValue = $this->Rubro->CurrentValue;
		$this->Subrubro->CurrentValue = NULL;
		$this->Subrubro->OldValue = $this->Subrubro->CurrentValue;
		$this->Marca->CurrentValue = NULL;
		$this->Marca->OldValue = $this->Marca->CurrentValue;
		$this->StockMinimo->CurrentValue = NULL;
		$this->StockMinimo->OldValue = $this->StockMinimo->CurrentValue;
		$this->Costo->CurrentValue = NULL;
		$this->Costo->OldValue = $this->Costo->CurrentValue;
		$this->Precio1->CurrentValue = NULL;
		$this->Precio1->OldValue = $this->Precio1->CurrentValue;
		$this->Precio2->CurrentValue = NULL;
		$this->Precio2->OldValue = $this->Precio2->CurrentValue;
		$this->Precio3->CurrentValue = NULL;
		$this->Precio3->OldValue = $this->Precio3->CurrentValue;
	}

	// Load form values
	function LoadFormValues() {

		// Load from form
		global $objForm;
		if (!$this->Codigo->FldIsDetailKey) {
			$this->Codigo->setFormValue($objForm->GetValue("x_Codigo"));
		}
		if (!$this->Nombre->FldIsDetailKey) {
			$this->Nombre->setFormValue($objForm->GetValue("x_Nombre"));
		}
		if (!$this->Rubro->FldIsDetailKey) {
			$this->Rubro->setFormValue($objForm->GetValue("x_Rubro"));
		}
		if (!$this->Subrubro->FldIsDetailKey) {
			$this->Subrubro->setFormValue($objForm->GetValue("x_Subrubro"));
		}
		if (!$this->Marca->FldIsDetailKey) {
			$this->Marca->setFormValue($objForm->GetValue("x_Marca"));
		}
		if (!$this->StockMinimo->FldIsDetailKey) {
			$this->StockMinimo->setFormValue($objForm->GetValue("x_StockMinimo"));
		}
		if (!$this->Costo->FldIsDetailKey) {
			$this->Costo->setFormValue($objForm->GetValue("x_Costo"));
		}
		if (!$this->Precio1->FldIsDetailKey) {
			$this->Precio1->setFormValue($objForm->GetValue("x_Precio1"));
		}
		if (!$this->Precio2->FldIsDetailKey) {
			$this->Precio2->setFormValue($objForm->GetValue("x_Precio2"));
		}
		if (!$this->Precio3->FldIsDetailKey) {
			$this->Precio3->setFormValue($objForm->GetValue("x_Precio3"));
		}
	}

	// Restore form values
	function RestoreFormValues() {
		global $objForm;
		$this->LoadOldRecord();
		$this->Codigo->CurrentValue = $this->Codigo->FormValue;
		$this->Nombre->CurrentValue = $this->Nombre->FormValue;
		$this->Rubro->CurrentValue = $this->Rubro->FormValue;
		$this->Subrubro->CurrentValue = $this->Subrubro->FormValue;
		$this->Marca->CurrentValue = $this->Marca->FormValue;
		$this->StockMinimo->CurrentValue = $this->StockMinimo->FormValue;
		$this->Costo->CurrentValue = $this->Costo->FormValue;
		$this->Precio1->CurrentValue = $this->Precio1->FormValue;
		$this->Precio2->CurrentValue = $this->Precio2->FormValue;
		$this->Precio3->CurrentValue = $this->Precio3->FormValue;
	}

	// Load row based on key values
	function LoadRow() {
		global $conn, $Security, $Language;
		$sFilter = $this->KeyFilter();

		// Call Row Selecting event
		$this->Row_Selecting($sFilter);

		// Load SQL based on filter
		$this->CurrentFilter = $sFilter;
		$sSql = $this->SQL();
		$res = FALSE;
		$rs = ew_LoadRecordset($sSql);
		if ($rs && !$rs->EOF) {
			$res = TRUE;
			$this->LoadRowValues($rs); // Load row values
			$rs->Close();
		}
		return $res;
	}

	// Load row values from recordset
	function LoadRowValues(&$rs) {
		global $conn;
		if (!$rs || $rs->EOF) return;

		// Call Row Selected event
		$row = &$rs->fields;
		$this->Row_Selected($row);
		$this->id->setDbValue($rs->fields('id'));
		$this->Codigo->setDbValue($rs->fields('Codigo'));
		$this->Nombre->setDbValue($rs->fields('Nombre'));
		$this->Rubro->setDbValue($rs->fields('Rubro'));
		$this->Subrubro->setDbValue($rs->fields('Subrubro'));
		$this->Marca->setDbValue($rs->fields('Marca'));
		$this->StockMinimo->setDbValue($rs->fields('StockMinimo'));
		$this->Costo->setDbValue($rs->fields('Costo'));
		$this->Precio1->setDbValue($rs->fields('Precio1'));
		$this->Precio2->setDbValue($rs->fields('Precio2'));
		$this->Precio3->setDbValue($rs->fields('Precio3'));
	}

	// Load DbValue from recordset
	function LoadDbValues(&$rs) {
		if (!$rs || !is_array($rs) && $rs->EOF) return;
		$row = is_array($rs) ? $rs : $rs->fields;
		$this->id->DbValue = $row['id'];
		$this->Codigo->DbValue = $row['Codigo'];
		$this->Nombre->DbValue = $row['Nombre'];
		$this->Rubro->DbValue = $row['Rubro'];
		$this->Subrubro->DbValue = $row['Subrubro'];
		$this->Marca->DbValue = $row['Marca'];
		$this->StockMinimo->DbValue = $row['StockMinimo'];
		$this->Costo->DbValue = $row['Costo'];
		$this->Precio1->DbValue = $row['Precio1'];
		$this->Precio2->DbValue = $row['Precio2'];
		$this->Precio3->DbValue = $row['Precio3'];
	}

	// Load old record
	function LoadOldRecord() {

		// Load key values from Session
		$bValidKey = TRUE;
		if (strval($this->getKey("id")) <> "")
			$this->id->CurrentValue = $this->getKey("id"); // id
		else
			$bValidKey = FALSE;

		// Load old recordset
		if ($bValidKey) {
			$this->CurrentFilter = $this->KeyFilter();
			$sSql = $this->SQL();
			$this->OldRecordset = ew_LoadRecordset($sSql);
			$this->LoadRowValues($this->OldRecordset); // Load row values
		} else {
			$this->OldRecordset = NULL;
		}
		return $bValidKey;
	}

	// Render row values based on field settings
	function RenderRow() {
		global $conn, $Security, $Language;
		global $gsLanguage;

		// Initialize URLs
		// Convert decimal values if posted back

		if ($this->Costo->FormValue == $this->Costo->CurrentValue && is_numeric(ew_StrToFloat($this->Costo->CurrentValue)))
			$this->Costo->CurrentValue = ew_StrToFloat($this->Costo->CurrentValue);

		// Convert decimal values if posted back
		if ($this->Precio1->FormValue == $this->Precio1->CurrentValue && is_numeric(ew_StrToFloat($this->Precio1->CurrentValue)))
			$this->Precio1->CurrentValue = ew_StrToFloat($this->Precio1->CurrentValue);

		// Convert decimal values if posted back
		if ($this->Precio2->FormValue == $this->Precio2->CurrentValue && is_numeric(ew_StrToFloat($this->Precio2->CurrentValue)))
			$this->Precio2->CurrentValue = ew_StrToFloat($this->Precio2->CurrentValue);

		// Convert decimal values if posted back
		if ($this->Precio3->FormValue == $this->Precio3->CurrentValue && is_numeric(ew_StrToFloat($this->Precio3->CurrentValue)))
			$this->Precio3->CurrentValue = ew_StrToFloat($this->Precio3->CurrentValue);

		// Call Row_Rendering event
		$this->Row_Rendering();

		// Common render codes for all row types
		// id
		// Codigo
		// Nombre
		// Rubro
		// Subrubro
		// Marca
		// StockMinimo
		// Costo
		// Precio1
		// Precio2
		// Precio3

		if ($this->RowType == EW_ROWTYPE_VIEW) { // View row

			// id
			$this->id->ViewValue = $this->id->CurrentValue;
			$this->id->ViewCustomAttributes = "";

			// Codigo
			$this->Codigo->ViewValue = $this->Codigo->CurrentValue;
			$this->Codigo->ViewCustomAttributes = "";

			// Nombre
			$this->Nombre->ViewValue = $this->Nombre->CurrentValue;
			$this->Nombre->ViewCustomAttributes = "";

			// Rubro
			if (strval($this->Rubro->CurrentValue) <> "") {
				$sFilterWrk = "`id`" . ew_SearchString("=", $this->Rubro->CurrentValue, EW_DATATYPE_NUMBER);
			$sSqlWrk = "SELECT `id`, `Nombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `stock_rubro`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->Rubro, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$this->Rubro->ViewValue = $rswrk->fields('DispFld');
					$rswrk->Close();
				} else {
					$this->Rubro->ViewValue = $this->Rubro->CurrentValue;
				}
			} else {
				$this->Rubro->ViewValue = NULL;
			}
			$this->Rubro->ViewCustomAttributes = "";

			// Subrubro
			if (strval($this->Subrubro->CurrentValue) <> "") {
				$sFilterWrk = "`id`" . ew_SearchString("=", $this->Subrubro->CurrentValue, EW_DATATYPE_NUMBER);
			$sSqlWrk = "SELECT `id`, `Nombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `stock_subrubro`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->Subrubro, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$this->Subrubro->ViewValue = $rswrk->fields('DispFld');
					$rswrk->Close();
				} else {
					$this->Subrubro->ViewValue = $this->Subrubro->CurrentValue;
				}
			} else {
				$this->Subrubro->ViewValue = NULL;
			}
			$this->Subrubro->ViewCustomAttributes = "";

			// Marca
			if (strval($this->Marca->CurrentValue) <> "") {
				$sFilterWrk = "`id`" . ew_SearchString("=", $this->Marca->CurrentValue, EW_DATATYPE_NUMBER);
			$sSqlWrk = "SELECT `id`, `Nombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `stock_marca`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->Marca, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$this->Marca->ViewValue = $rswrk->fields('DispFld');
					$rswrk->Close();
				} else {
					$this->Marca->ViewValue = $this->Marca->CurrentValue;
				}
			} else {
				$this->Marca->ViewValue = NULL;
			}
			$this->Marca->ViewCustomAttributes = "";

			// StockMinimo
			$this->StockMinimo->ViewValue = $this->StockMinimo->CurrentValue;
			$this->StockMinimo->ViewCustomAttributes = "";

			// Costo
			$this->Costo->ViewValue = $this->Costo->CurrentValue;
			$this->Costo->ViewCustomAttributes = "";

			// Precio1
			$this->Precio1->ViewValue = $this->Precio1->CurrentValue;
			$this->Precio1->ViewCustomAttributes = "";

			// Precio2
			$this->Precio2->ViewValue = $this->Precio2->CurrentValue;
			$this->Precio2->ViewCustomAttributes = "";

			// Precio3
			$this->Precio3->ViewValue = $this->Precio3->CurrentValue;
			$this->Precio3->ViewCustomAttributes = "";

			// Codigo
			$this->Codigo->LinkCustomAttributes = "";
			$this->Codigo->HrefValue = "";
			$this->Codigo->TooltipValue = "";

			// Nombre
			$this->Nombre->LinkCustomAttributes = "";
			$this->Nombre->HrefValue = "";
			$this->Nombre->TooltipValue = "";

			// Rubro
			$this->Rubro->LinkCustomAttributes = "";
			$this->Rubro->HrefValue = "";
			$this->Rubro->TooltipValue = "";

			// Subrubro
			$this->Subrubro->LinkCustomAttributes = "";
			$this->Subrubro->HrefValue = "";
			$this->Subrubro->TooltipValue = "";

			// Marca
			$this->Marca->LinkCustomAttributes = "";
			$this->Marca->HrefValue = "";
			$this->Marca->TooltipValue = "";

			// StockMinimo
			$this->StockMinimo->LinkCustomAttributes = "";
			$this->StockMinimo->HrefValue = "";
			$this->StockMinimo->TooltipValue = "";

			// Costo
			$this->Costo->LinkCustomAttributes = "";
			$this->Costo->HrefValue = "";
			$this->Costo->TooltipValue = "";

			// Precio1
			$this->Precio1->LinkCustomAttributes = "";
			$this->Precio1->HrefValue = "";
			$this->Precio1->TooltipValue = "";

			// Precio2
			$this->Precio2->LinkCustomAttributes = "";
			$this->Precio2->HrefValue = "";
			$this->Precio2->TooltipValue = "";

			// Precio3
			$this->Precio3->LinkCustomAttributes = "";
			$this->Precio3->HrefValue = "";
			$this->Precio3->TooltipValue = "";
		} elseif ($this->RowType == EW_ROWTYPE_ADD) { // Add row

			// Codigo
			$this->Codigo->EditCustomAttributes = "";
			$this->Codigo->EditValue = ew_HtmlEncode($this->Codigo->CurrentValue);
			$this->Codigo->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->Codigo->FldCaption()));

			// Nombre
			$this->Nombre->EditCustomAttributes = "";
			$this->Nombre->EditValue = ew_HtmlEncode($this->Nombre->CurrentValue);
			$this->Nombre->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->Nombre->FldCaption()));

			// Rubro
			$this->Rubro->EditCustomAttributes = "";
			if (trim(strval($this->Rubro->CurrentValue)) == "") {
				$sFilterWrk = "0=1";
			} else {
				$sFilterWrk = "`id`" . ew_SearchString("=", $this->Rubro->CurrentValue, EW_DATATYPE_NUMBER);
			}
			$sSqlWrk = "SELECT `id`, `Nombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld`, '' AS `SelectFilterFld`, '' AS `SelectFilterFld2`, '' AS `SelectFilterFld3`, '' AS `SelectFilterFld4` FROM `stock_rubro`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->Rubro, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect"), "", "", "", "", "", "", ""));
			$this->Rubro->EditValue = $arwrk;

			// Subrubro
			$this->Subrubro->EditCustomAttributes = "";
			if (trim(strval($this->Subrubro->CurrentValue)) == "") {
				$sFilterWrk = "0=1";
			} else {
				$sFilterWrk = "`id`" . ew_SearchString("=", $this->Subrubro->CurrentValue, EW_DATATYPE_NUMBER);
			}
			$sSqlWrk = "SELECT `id`, `Nombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld`, `Rubro` AS `SelectFilterFld`, '' AS `SelectFilterFld2`, '' AS `SelectFilterFld3`, '' AS `SelectFilterFld4` FROM `stock_subrubro`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->Subrubro, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect"), "", "", "", "", "", "", ""));
			$this->Subrubro->EditValue = $arwrk;

			// Marca
			$this->Marca->EditCustomAttributes = "";
			if (trim(strval($this->Marca->CurrentValue)) == "") {
				$sFilterWrk = "0=1";
			} else {
				$sFilterWrk = "`id`" . ew_SearchString("=", $this->Marca->CurrentValue, EW_DATATYPE_NUMBER);
			}
			$sSqlWrk = "SELECT `id`, `Nombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld`, '' AS `SelectFilterFld`, '' AS `SelectFilterFld2`, '' AS `SelectFilterFld3`, '' AS `SelectFilterFld4` FROM `stock_marca`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->Marca, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect"), "", "", "", "", "", "", ""));
			$this->Marca->EditValue = $arwrk;

			// StockMinimo
			$this->StockMinimo->EditCustomAttributes = "";
			$this->StockMinimo->EditValue = ew_HtmlEncode($this->StockMinimo->CurrentValue);
			$this->StockMinimo->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->StockMinimo->FldCaption()));

			// Costo
			$this->Costo->EditCustomAttributes = "";
			$this->Costo->EditValue = ew_HtmlEncode($this->Costo->CurrentValue);
			$this->Costo->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->Costo->FldCaption()));
			if (strval($this->Costo->EditValue) <> "" && is_numeric($this->Costo->EditValue)) $this->Costo->EditValue = ew_FormatNumber($this->Costo->EditValue, -2, -1, -2, 0);

			// Precio1
			$this->Precio1->EditCustomAttributes = "";
			$this->Precio1->EditValue = ew_HtmlEncode($this->Precio1->CurrentValue);
			$this->Precio1->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->Precio1->FldCaption()));
			if (strval($this->Precio1->EditValue) <> "" && is_numeric($this->Precio1->EditValue)) $this->Precio1->EditValue = ew_FormatNumber($this->Precio1->EditValue, -2, -1, -2, 0);

			// Precio2
			$this->Precio2->EditCustomAttributes = "";
			$this->Precio2->EditValue = ew_HtmlEncode($this->Precio2->CurrentValue);
			$this->Precio2->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->Precio2->FldCaption()));
			if (strval($this->Precio2->EditValue) <> "" && is_numeric($this->Precio2->EditValue)) $this->Precio2->EditValue = ew_FormatNumber($this->Precio2->EditValue, -2, -1, -2, 0);

			// Precio3
			$this->Precio3->EditCustomAttributes = "";
			$this->Precio3->EditValue = ew_HtmlEncode($this->Precio3->CurrentValue);
			$this->Precio3->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->Precio3->FldCaption()));
			if (strval($this->Precio3->EditValue) <> "" && is_numeric($this->Precio3->EditValue)) $this->Precio3->EditValue = ew_FormatNumber($this->Precio3->EditValue, -2, -1, -2, 0);

			// Edit refer script
			// Codigo

			$this->Codigo->HrefValue = "";

			// Nombre
			$this->Nombre->HrefValue = "";

			// Rubro
			$this->Rubro->HrefValue = "";

			// Subrubro
			$this->Subrubro->HrefValue = "";

			// Marca
			$this->Marca->HrefValue = "";

			// StockMinimo
			$this->StockMinimo->HrefValue = "";

			// Costo
			$this->Costo->HrefValue = "";

			// Precio1
			$this->Precio1->HrefValue = "";

			// Precio2
			$this->Precio2->HrefValue = "";

			// Precio3
			$this->Precio3->HrefValue = "";
		}
		if ($this->RowType == EW_ROWTYPE_ADD ||
			$this->RowType == EW_ROWTYPE_EDIT ||
			$this->RowType == EW_ROWTYPE_SEARCH) { // Add / Edit / Search row
			$this->SetupFieldTitles();
		}

		// Call Row Rendered event
		if ($this->RowType <> EW_ROWTYPE_AGGREGATEINIT)
			$this->Row_Rendered();
	}

	// Validate form
	function ValidateForm() {
		global $Language, $gsFormError;

		// Initialize form error message
		$gsFormError = "";

		// Check if validation required
		if (!EW_SERVER_VALIDATE)
			return ($gsFormError == "");
		if (!ew_CheckInteger($this->StockMinimo->FormValue)) {
			ew_AddMessage($gsFormError, $this->StockMinimo->FldErrMsg());
		}
		if (!ew_CheckNumber($this->Costo->FormValue)) {
			ew_AddMessage($gsFormError, $this->Costo->FldErrMsg());
		}
		if (!ew_CheckNumber($this->Precio1->FormValue)) {
			ew_AddMessage($gsFormError, $this->Precio1->FldErrMsg());
		}
		if (!ew_CheckNumber($this->Precio2->FormValue)) {
			ew_AddMessage($gsFormError, $this->Precio2->FldErrMsg());
		}
		if (!ew_CheckNumber($this->Precio3->FormValue)) {
			ew_AddMessage($gsFormError, $this->Precio3->FldErrMsg());
		}

		// Return validate result
		$ValidateForm = ($gsFormError == "");

		// Call Form_CustomValidate event
		$sFormCustomError = "";
		$ValidateForm = $ValidateForm && $this->Form_CustomValidate($sFormCustomError);
		if ($sFormCustomError <> "") {
			ew_AddMessage($gsFormError, $sFormCustomError);
		}
		return $ValidateForm;
	}

	// Add record
	function AddRow($rsold = NULL) {
		global $conn, $Language, $Security;
		if ($this->Codigo->CurrentValue <> "") { // Check field with unique index
			$sFilter = "(Codigo = '" . ew_AdjustSql($this->Codigo->CurrentValue) . "')";
			$rsChk = $this->LoadRs($sFilter);
			if ($rsChk && !$rsChk->EOF) {
				$sIdxErrMsg = str_replace("%f", $this->Codigo->FldCaption(), $Language->Phrase("DupIndex"));
				$sIdxErrMsg = str_replace("%v", $this->Codigo->CurrentValue, $sIdxErrMsg);
				$this->setFailureMessage($sIdxErrMsg);
				$rsChk->Close();
				return FALSE;
			}
		}

		// Load db values from rsold
		if ($rsold) {
			$this->LoadDbValues($rsold);
		}
		$rsnew = array();

		// Codigo
		$this->Codigo->SetDbValueDef($rsnew, $this->Codigo->CurrentValue, NULL, FALSE);

		// Nombre
		$this->Nombre->SetDbValueDef($rsnew, $this->Nombre->CurrentValue, NULL, FALSE);

		// Rubro
		$this->Rubro->SetDbValueDef($rsnew, $this->Rubro->CurrentValue, NULL, FALSE);

		// Subrubro
		$this->Subrubro->SetDbValueDef($rsnew, $this->Subrubro->CurrentValue, NULL, FALSE);

		// Marca
		$this->Marca->SetDbValueDef($rsnew, $this->Marca->CurrentValue, NULL, FALSE);

		// StockMinimo
		$this->StockMinimo->SetDbValueDef($rsnew, $this->StockMinimo->CurrentValue, NULL, FALSE);

		// Costo
		$this->Costo->SetDbValueDef($rsnew, $this->Costo->CurrentValue, NULL, FALSE);

		// Precio1
		$this->Precio1->SetDbValueDef($rsnew, $this->Precio1->CurrentValue, NULL, FALSE);

		// Precio2
		$this->Precio2->SetDbValueDef($rsnew, $this->Precio2->CurrentValue, NULL, FALSE);

		// Precio3
		$this->Precio3->SetDbValueDef($rsnew, $this->Precio3->CurrentValue, NULL, FALSE);

		// Call Row Inserting event
		$rs = ($rsold == NULL) ? NULL : $rsold->fields;
		$bInsertRow = $this->Row_Inserting($rs, $rsnew);
		if ($bInsertRow) {
			$conn->raiseErrorFn = 'ew_ErrorFn';
			$AddRow = $this->Insert($rsnew);
			$conn->raiseErrorFn = '';
			if ($AddRow) {
			}
		} else {
			if ($this->getSuccessMessage() <> "" || $this->getFailureMessage() <> "") {

				// Use the message, do nothing
			} elseif ($this->CancelMessage <> "") {
				$this->setFailureMessage($this->CancelMessage);
				$this->CancelMessage = "";
			} else {
				$this->setFailureMessage($Language->Phrase("InsertCancelled"));
			}
			$AddRow = FALSE;
		}

		// Get insert id if necessary
		if ($AddRow) {
			$this->id->setDbValue($conn->Insert_ID());
			$rsnew['id'] = $this->id->DbValue;
		}
		if ($AddRow) {

			// Call Row Inserted event
			$rs = ($rsold == NULL) ? NULL : $rsold->fields;
			$this->Row_Inserted($rs, $rsnew);
		}
		return $AddRow;
	}

	// Set up Breadcrumb
	function SetupBreadcrumb() {
		global $Breadcrumb, $Language;
		$Breadcrumb = new cBreadcrumb();
		$Breadcrumb->Add("list", $this->TableVar, "stock_articulolist.php", $this->TableVar, TRUE);
		$PageId = ($this->CurrentAction == "C") ? "Copy" : "Add";
		$Breadcrumb->Add("add", $PageId, ew_CurrentUrl());
	}

	// Page Load event
	function Page_Load() {

		//echo "Page Load";
	}

	// Page Unload event
	function Page_Unload() {

		//echo "Page Unload";
	}

	// Page Redirecting event
	function Page_Redirecting(&$url) {

		// Example:
		//$url = "your URL";

	}

	// Message Showing event
	// $type = ''|'success'|'failure'|'warning'
	function Message_Showing(&$msg, $type) {
		if ($type == 'success') {

			//$msg = "your success message";
		} elseif ($type == 'failure') {

			//$msg = "your failure message";
		} elseif ($type == 'warning') {

			//$msg = "your warning message";
		} else {

			//$msg = "your message";
		}
	}

	// Page Render event
	function Page_Render() {

		//echo "Page Render";
	}

	// Page Data Rendering event
	function Page_DataRendering(&$header) {

		// Example:
		//$header = "your header";

	}

	// Page Data Rendered event
	function Page_DataRendered(&$footer) {

		// Example:
		//$footer = "your footer";

	}

	// Form Custom Validate event
	function Form_CustomValidate(&$CustomError) {

		// Return error message in CustomError
		return TRUE;
	}
}
?>
<?php ew_Header(FALSE) ?>
<?php

// Create page object
if (!isset($stock_articulo_add)) $stock_articulo_add = new cstock_articulo_add();

// Page init
$stock_articulo_add->Page_Init();

// Page main
$stock_articulo_add->Page_Main();

// Global Page Rendering event (in userfn*.php)
Page_Rendering();

// Page Rendering event
$stock_articulo_add->Page_Render();
?>
<?php include_once "header.php" ?>
<script type="text/javascript">

// Page object
var stock_articulo_add = new ew_Page("stock_articulo_add");
stock_articulo_add.PageID = "add"; // Page ID
var EW_PAGE_ID = stock_articulo_add.PageID; // For backward compatibility

// Form object
var fstock_articuloadd = new ew_Form("fstock_articuloadd");

// Validate form
fstock_articuloadd.Validate = function() {
	if (!this.ValidateRequired)
		return true; // Ignore validation
	var $ = jQuery, fobj = this.GetForm(), $fobj = $(fobj);
	this.PostAutoSuggest();
	if ($fobj.find("#a_confirm").val() == "F")
		return true;
	var elm, felm, uelm, addcnt = 0;
	var $k = $fobj.find("#" + this.FormKeyCountName); // Get key_count
	var rowcnt = ($k[0]) ? parseInt($k.val(), 10) : 1;
	var startcnt = (rowcnt == 0) ? 0 : 1; // Check rowcnt == 0 => Inline-Add
	var gridinsert = $fobj.find("#a_list").val() == "gridinsert";
	for (var i = startcnt; i <= rowcnt; i++) {
		var infix = ($k[0]) ? String(i) : "";
		$fobj.data("rowindex", infix);
			elm = this.GetElements("x" + infix + "_StockMinimo");
			if (elm && !ew_CheckInteger(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($stock_articulo->StockMinimo->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_Costo");
			if (elm && !ew_CheckNumber(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($stock_articulo->Costo->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_Precio1");
			if (elm && !ew_CheckNumber(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($stock_articulo->Precio1->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_Precio2");
			if (elm && !ew_CheckNumber(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($stock_articulo->Precio2->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_Precio3");
			if (elm && !ew_CheckNumber(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($stock_articulo->Precio3->FldErrMsg()) ?>");

			// Set up row object
			ew_ElementsToRow(fobj);

			// Fire Form_CustomValidate event
			if (!this.Form_CustomValidate(fobj))
				return false;
	}

	// Process detail forms
	var dfs = $fobj.find("input[name='detailpage']").get();
	for (var i = 0; i < dfs.length; i++) {
		var df = dfs[i], val = df.value;
		if (val && ewForms[val])
			if (!ewForms[val].Validate())
				return false;
	}
	return true;
}

// Form_CustomValidate event
fstock_articuloadd.Form_CustomValidate = 
 function(fobj) { // DO NOT CHANGE THIS LINE!

 	// Your custom validation code here, return false if invalid. 
 	return true;
 }

// Use JavaScript validation or not
<?php if (EW_CLIENT_VALIDATE) { ?>
fstock_articuloadd.ValidateRequired = true;
<?php } else { ?>
fstock_articuloadd.ValidateRequired = false; 
<?php } ?>

// Dynamic selection lists
fstock_articuloadd.Lists["x_Rubro"] = {"LinkField":"x_id","Ajax":true,"AutoFill":false,"DisplayFields":["x_Nombre","","",""],"ParentFields":[],"FilterFields":[],"Options":[]};
fstock_articuloadd.Lists["x_Subrubro"] = {"LinkField":"x_id","Ajax":true,"AutoFill":false,"DisplayFields":["x_Nombre","","",""],"ParentFields":["x_Rubro"],"FilterFields":["x_Rubro"],"Options":[]};
fstock_articuloadd.Lists["x_Marca"] = {"LinkField":"x_id","Ajax":true,"AutoFill":false,"DisplayFields":["x_Nombre","","",""],"ParentFields":[],"FilterFields":[],"Options":[]};

// Form object for search
</script>
<script type="text/javascript">

// Write your client script here, no need to add script tags.
</script>
<?php $Breadcrumb->Render(); ?>
<?php $stock_articulo_add->ShowPageHeader(); ?>
<?php
$stock_articulo_add->ShowMessage();
?>
<form name="fstock_articuloadd" id="fstock_articuloadd" class="ewForm form-horizontal" action="<?php echo ew_CurrentPage() ?>" method="post">
<input type="hidden" name="t" value="stock_articulo">
<input type="hidden" name="a_add" id="a_add" value="A">
<table class="ewGrid"><tr><td>
<table id="tbl_stock_articuloadd" class="table table-bordered table-striped">
<?php if ($stock_articulo->Codigo->Visible) { // Codigo ?>
	<tr id="r_Codigo">
		<td><span id="elh_stock_articulo_Codigo"><?php echo $stock_articulo->Codigo->FldCaption() ?></span></td>
		<td<?php echo $stock_articulo->Codigo->CellAttributes() ?>>
<span id="el_stock_articulo_Codigo" class="control-group">
<input type="text" data-field="x_Codigo" name="x_Codigo" id="x_Codigo" size="30" maxlength="20" placeholder="<?php echo $stock_articulo->Codigo->PlaceHolder ?>" value="<?php echo $stock_articulo->Codigo->EditValue ?>"<?php echo $stock_articulo->Codigo->EditAttributes() ?>>
</span>
<?php echo $stock_articulo->Codigo->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($stock_articulo->Nombre->Visible) { // Nombre ?>
	<tr id="r_Nombre">
		<td><span id="elh_stock_articulo_Nombre"><?php echo $stock_articulo->Nombre->FldCaption() ?></span></td>
		<td<?php echo $stock_articulo->Nombre->CellAttributes() ?>>
<span id="el_stock_articulo_Nombre" class="control-group">
<input type="text" data-field="x_Nombre" name="x_Nombre" id="x_Nombre" size="30" maxlength="20" placeholder="<?php echo $stock_articulo->Nombre->PlaceHolder ?>" value="<?php echo $stock_articulo->Nombre->EditValue ?>"<?php echo $stock_articulo->Nombre->EditAttributes() ?>>
</span>
<?php echo $stock_articulo->Nombre->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($stock_articulo->Rubro->Visible) { // Rubro ?>
	<tr id="r_Rubro">
		<td><span id="elh_stock_articulo_Rubro"><?php echo $stock_articulo->Rubro->FldCaption() ?></span></td>
		<td<?php echo $stock_articulo->Rubro->CellAttributes() ?>>
<span id="el_stock_articulo_Rubro" class="control-group">
<?php $stock_articulo->Rubro->EditAttrs["onchange"] = "ew_UpdateOpt.call(this, ['x_Subrubro']); " . @$stock_articulo->Rubro->EditAttrs["onchange"]; ?>
<select data-field="x_Rubro" id="x_Rubro" name="x_Rubro"<?php echo $stock_articulo->Rubro->EditAttributes() ?>>
<?php
if (is_array($stock_articulo->Rubro->EditValue)) {
	$arwrk = $stock_articulo->Rubro->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($stock_articulo->Rubro->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
<?php
$sSqlWrk = "SELECT `id`, `Nombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `stock_rubro`";
$sWhereWrk = "";

// Call Lookup selecting
$stock_articulo->Lookup_Selecting($stock_articulo->Rubro, $sWhereWrk);
if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
?>
<input type="hidden" name="s_x_Rubro" id="s_x_Rubro" value="s=<?php echo ew_Encrypt($sSqlWrk) ?>&amp;f0=<?php echo ew_Encrypt("`id` = {filter_value}"); ?>&amp;t0=3">
</span>
<?php echo $stock_articulo->Rubro->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($stock_articulo->Subrubro->Visible) { // Subrubro ?>
	<tr id="r_Subrubro">
		<td><span id="elh_stock_articulo_Subrubro"><?php echo $stock_articulo->Subrubro->FldCaption() ?></span></td>
		<td<?php echo $stock_articulo->Subrubro->CellAttributes() ?>>
<span id="el_stock_articulo_Subrubro" class="control-group">
<select data-field="x_Subrubro" id="x_Subrubro" name="x_Subrubro"<?php echo $stock_articulo->Subrubro->EditAttributes() ?>>
<?php
if (is_array($stock_articulo->Subrubro->EditValue)) {
	$arwrk = $stock_articulo->Subrubro->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($stock_articulo->Subrubro->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
<?php
$sSqlWrk = "SELECT `id`, `Nombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `stock_subrubro`";
$sWhereWrk = "{filter}";

// Call Lookup selecting
$stock_articulo->Lookup_Selecting($stock_articulo->Subrubro, $sWhereWrk);
if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
?>
<input type="hidden" name="s_x_Subrubro" id="s_x_Subrubro" value="s=<?php echo ew_Encrypt($sSqlWrk) ?>&amp;f0=<?php echo ew_Encrypt("`id` = {filter_value}"); ?>&amp;t0=3&amp;f1=<?php echo ew_Encrypt("`Rubro` IN ({filter_value})"); ?>&amp;t1=3">
</span>
<?php echo $stock_articulo->Subrubro->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($stock_articulo->Marca->Visible) { // Marca ?>
	<tr id="r_Marca">
		<td><span id="elh_stock_articulo_Marca"><?php echo $stock_articulo->Marca->FldCaption() ?></span></td>
		<td<?php echo $stock_articulo->Marca->CellAttributes() ?>>
<span id="el_stock_articulo_Marca" class="control-group">
<select data-field="x_Marca" id="x_Marca" name="x_Marca"<?php echo $stock_articulo->Marca->EditAttributes() ?>>
<?php
if (is_array($stock_articulo->Marca->EditValue)) {
	$arwrk = $stock_articulo->Marca->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($stock_articulo->Marca->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
<?php
$sSqlWrk = "SELECT `id`, `Nombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `stock_marca`";
$sWhereWrk = "";

// Call Lookup selecting
$stock_articulo->Lookup_Selecting($stock_articulo->Marca, $sWhereWrk);
if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
?>
<input type="hidden" name="s_x_Marca" id="s_x_Marca" value="s=<?php echo ew_Encrypt($sSqlWrk) ?>&amp;f0=<?php echo ew_Encrypt("`id` = {filter_value}"); ?>&amp;t0=3">
</span>
<?php echo $stock_articulo->Marca->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($stock_articulo->StockMinimo->Visible) { // StockMinimo ?>
	<tr id="r_StockMinimo">
		<td><span id="elh_stock_articulo_StockMinimo"><?php echo $stock_articulo->StockMinimo->FldCaption() ?></span></td>
		<td<?php echo $stock_articulo->StockMinimo->CellAttributes() ?>>
<span id="el_stock_articulo_StockMinimo" class="control-group">
<input type="text" data-field="x_StockMinimo" name="x_StockMinimo" id="x_StockMinimo" size="30" placeholder="<?php echo $stock_articulo->StockMinimo->PlaceHolder ?>" value="<?php echo $stock_articulo->StockMinimo->EditValue ?>"<?php echo $stock_articulo->StockMinimo->EditAttributes() ?>>
</span>
<?php echo $stock_articulo->StockMinimo->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($stock_articulo->Costo->Visible) { // Costo ?>
	<tr id="r_Costo">
		<td><span id="elh_stock_articulo_Costo"><?php echo $stock_articulo->Costo->FldCaption() ?></span></td>
		<td<?php echo $stock_articulo->Costo->CellAttributes() ?>>
<span id="el_stock_articulo_Costo" class="control-group">
<input type="text" data-field="x_Costo" name="x_Costo" id="x_Costo" size="30" placeholder="<?php echo $stock_articulo->Costo->PlaceHolder ?>" value="<?php echo $stock_articulo->Costo->EditValue ?>"<?php echo $stock_articulo->Costo->EditAttributes() ?>>
</span>
<?php echo $stock_articulo->Costo->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($stock_articulo->Precio1->Visible) { // Precio1 ?>
	<tr id="r_Precio1">
		<td><span id="elh_stock_articulo_Precio1"><?php echo $stock_articulo->Precio1->FldCaption() ?></span></td>
		<td<?php echo $stock_articulo->Precio1->CellAttributes() ?>>
<span id="el_stock_articulo_Precio1" class="control-group">
<input type="text" data-field="x_Precio1" name="x_Precio1" id="x_Precio1" size="30" placeholder="<?php echo $stock_articulo->Precio1->PlaceHolder ?>" value="<?php echo $stock_articulo->Precio1->EditValue ?>"<?php echo $stock_articulo->Precio1->EditAttributes() ?>>
</span>
<?php echo $stock_articulo->Precio1->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($stock_articulo->Precio2->Visible) { // Precio2 ?>
	<tr id="r_Precio2">
		<td><span id="elh_stock_articulo_Precio2"><?php echo $stock_articulo->Precio2->FldCaption() ?></span></td>
		<td<?php echo $stock_articulo->Precio2->CellAttributes() ?>>
<span id="el_stock_articulo_Precio2" class="control-group">
<input type="text" data-field="x_Precio2" name="x_Precio2" id="x_Precio2" size="30" placeholder="<?php echo $stock_articulo->Precio2->PlaceHolder ?>" value="<?php echo $stock_articulo->Precio2->EditValue ?>"<?php echo $stock_articulo->Precio2->EditAttributes() ?>>
</span>
<?php echo $stock_articulo->Precio2->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($stock_articulo->Precio3->Visible) { // Precio3 ?>
	<tr id="r_Precio3">
		<td><span id="elh_stock_articulo_Precio3"><?php echo $stock_articulo->Precio3->FldCaption() ?></span></td>
		<td<?php echo $stock_articulo->Precio3->CellAttributes() ?>>
<span id="el_stock_articulo_Precio3" class="control-group">
<input type="text" data-field="x_Precio3" name="x_Precio3" id="x_Precio3" size="30" placeholder="<?php echo $stock_articulo->Precio3->PlaceHolder ?>" value="<?php echo $stock_articulo->Precio3->EditValue ?>"<?php echo $stock_articulo->Precio3->EditAttributes() ?>>
</span>
<?php echo $stock_articulo->Precio3->CustomMsg ?></td>
	</tr>
<?php } ?>
</table>
</td></tr></table>
<button class="btn btn-primary ewButton" name="btnAction" id="btnAction" type="submit"><?php echo $Language->Phrase("AddBtn") ?></button>
</form>
<script type="text/javascript">
fstock_articuloadd.Init();
<?php if (EW_MOBILE_REFLOW && ew_IsMobile()) { ?>
ew_Reflow();
<?php } ?>
</script>
<?php
$stock_articulo_add->ShowPageFooter();
if (EW_DEBUG_ENABLED)
	echo ew_DebugMsg();
?>
<script type="text/javascript">

// Write your table-specific startup script here
// document.write("page loaded");

</script>
<?php include_once "footer.php" ?>
<?php
$stock_articulo_add->Page_Terminate();
?>
